<script setup lang="ts">
import { ref } from "vue";
import { staticConfig } from "./utils/hook";
import { useRenderIcon } from "@/components/ReIcon/src/hooks";
import { PureTableBar } from "@/components/RePureTableBar";
import Refresh from "@iconify-icons/ep/refresh";
import EditPen from "@iconify-icons/ep/edit-pen";
import { usePublicFormats } from "../../formats";
import AddFill from "@iconify-icons/ri/add-circle-line";

defineOptions({
  name: "dingtalkBanner"
});

const formRef = ref();

const {
  columns,
  openDialog,
  form,
  loading,
  onSearch,
  resetForm,
  dataList,
  pagination,
  onSizeChange,
  onCurrentChange,
  loadingConfig,
  handleDelete
} = staticConfig();

//从父级钩子里取东西
const { statusOptions, paymentMethodOptions } = usePublicFormats();
</script>

<template>
  <div>
    <PureTableBar title="banner管理" :columns="columns" @refresh="onSearch">
      <template #buttons>
        <el-button
          type="primary"
          :icon="useRenderIcon(AddFill)"
          @click="openDialog('新增')"
        >
          新增
        </el-button>
      </template>
      <pure-table
        v-if="dataList.length > 0"
        ref="tableRef"
        row-key="id"
        alignWhole="center"
        showOverflowTooltip
        :loading="loading"
        :loading-config="loadingConfig"
        :columns="columns"
        :data="dataList"
        :header-cell-style="{
          background: 'var(--el-fill-color-light)',
          color: 'var(--el-text-color-primary)'
        }"
        :pagination="pagination"
        @page-size-change="onSizeChange"
        @page-current-change="onCurrentChange"
      >
        <template #operation="{ row }">
          <el-button
            class="reset-margin"
            link
            type="primary"
            :icon="useRenderIcon(EditPen)"
            @click="openDialog('修改', row)"
          >
            修改
          </el-button>
          <el-popconfirm
            :title="`是否确认删除编号为${row.id}的这条数据`"
            @confirm="handleDelete(row)"
          >
            <template #reference>
              <el-button
                class="reset-margin"
                link
                type="primary"
                :size="size"
                :icon="useRenderIcon(Delete)"
                v-if="row.class_id == 1"
              >
                删除
              </el-button>
            </template>
          </el-popconfirm>
        </template>
      </pure-table>
    </PureTableBar>
  </div>
</template>
